/*
 * @FilePath: /data-and-structure-lv/10/queue.c
 * @Brief: 
 * @Version: 1.0
 * @Date: 2021-12-26 11:07:17
 * @Author: zsk
 * @Copyright: open source
 * @LastEditors: zsk
 * @LastEditTime: 2021-12-26 11:13:50
 */
#include <stdio.h>

#define N 1024
typedef int ElementType;

typedef struct Queue_Tag
{
    ElementType q[N];
    int tail;
    int head;
} Queue;

void enqueue(Queue *q, ElementType x)
{
    q->q[q->tail] = x;
    if (q->tail == N - 1)
        q->tail = 0;
    else
        q->tail += 1;
}

ElementType dequeue(Queue *q)
{
    ElementType x = q->q[q->head];
    if (q->head == N - 1)
    {
        /* code */
        q->head = 1;
    }
    else
        q->head += 1;
    return x;
}

void main()
{
    Queue q = {.head = 0, .tail = 0};
    Queue *qp = &q;
    for (int i = 0; i < N; i++)
    {
        enqueue(qp, i);
    }
    for (int i = 0; i < N; i++)
    {
        ElementType x = dequeue(qp);
        printf("%d ", x);
    }
    printf("\n");
}